package davidtps.godutch.adapter;

import java.util.List;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import davidtps.godutch.activity.R;
import davidtps.godutch.adapter.base.AdapterBase;
import davidtps.godutch.business.BusinessAccount;
import davidtps.godutch.business.BusinessConsume;
import davidtps.godutch.controls.SlideMenuViewItem;
import davidtps.godutch.model.ModelAccount;

public class AdapterAccountManagerView extends AdapterBase {
	private BusinessAccount mBusinessAccount;
	private BusinessConsume mBusinessConsume;
	
	private class Holder{
		ImageView ivAccountImage;
		TextView tvAccountName;
		TextView tvAccountStatisticsValue;
		TextView tvDealCountValue;
	}
	
	public AdapterAccountManagerView(Context pContext) {
		super(pContext, null);
		mBusinessAccount = new BusinessAccount(pContext);
		mBusinessConsume = new BusinessConsume(pContext);
		List<ModelAccount> _ModelAccounts = mBusinessAccount.queryNoHideAccounts();
		setList(_ModelAccounts);
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		Holder _Holder;
		if(convertView==null){
			convertView = getLayoutInflater().inflate(R.layout.layout_accountmanager_item, null, true);
			
			_Holder = new Holder();
			
			_Holder.ivAccountImage = (ImageView)convertView.findViewById(R.id.ivAccountImage);
			_Holder.tvAccountName = (TextView)convertView.findViewById(R.id.tvAccountName);
			_Holder.tvAccountStatisticsValue = (TextView)convertView.findViewById(R.id.tvAccountStatisticsValue);
			_Holder.tvDealCountValue = (TextView)convertView.findViewById(R.id.tvDealCountValue);
			convertView.setTag(_Holder);
		}else{
			_Holder = (Holder)convertView.getTag();
		}
		
		ModelAccount _ModelAccount =  (ModelAccount) getList().get(position);
		if(_ModelAccount.getIsDefaultAccount()==1){
			_Holder.ivAccountImage.setBackgroundResource(R.drawable.account_book_default);
		}else{
			_Holder.ivAccountImage.setBackgroundResource(R.drawable.account_book_big_icon);
		}
		_Holder.tvAccountName.setText(_ModelAccount.getAccountName());
		
		String[] _Strings = mBusinessConsume.getConsumeInfoByAccountId(_ModelAccount.getAccountId()+"");
		String _TotalConsume = _Strings[1];
		String _TotalNumberString = _Strings[0];
		
		_Holder.tvAccountStatisticsValue.setText(getContext().getString(R.string.account_manager_total_consume_money, new Object[]{_TotalConsume}));
		_Holder.tvDealCountValue.setText(getContext().getString(R.string.account_manager_total_consume_number, new Object[]{_TotalNumberString}));
		return convertView;
	}

}
